package
{
	import com.greensock.TweenLite;
	
	import flash.display.Bitmap;
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;

	public class Cloud
	{
		public var speed:Number;
		public var display:DisplayObject;
		public var possibleXLocations:int;
		public var possibleYLocations:int;
		
		public function Cloud(speed:Number, display:DisplayObject, parent:DisplayObjectContainer, possibleXLocations:int, possibleYLocations:int)
		{
			if(Math.abs(speed) < .1){
				speed = (speed < 0) ? -.1 : .1;
			}
			this.speed = speed;
			this.display = display;
			this.possibleXLocations = possibleXLocations;
			this.possibleYLocations = possibleYLocations;
			parent.addChild(display);
			
			display.x = possibleXLocations*Math.random();
			display.y = possibleXLocations*Math.random()/2;
			var randomScale:Number = Math.random();
			var scale:Number = .5 + Math.abs(speed*.8)*randomScale;
			display.scaleX = scale;
			display.scaleY = scale;
		}
		
		private function restart():void{
			display.x = (speed > 0) ? 0 : possibleXLocations;
			ready = true;
		} 
		
		public var ready:Boolean = true;
		public function step(delta:int):void{
			if(!ready){
				return;
			}
			
			if(this.display.x < 0 || this.display.x > possibleXLocations){
				ready = false;
				TweenLite.to(display, 3, {alpha: 0,
					onComplete: function():void{
						restart();
						TweenLite.to(display,3,{alpha:1});
					}
				});
			}
			
			this.display.x += Game.PPS*speed*delta / 1000;
		}
	}
}